<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="jl">节流</button>
    <script>
        let jl = document.getElementById('jl')
        function debounce(fn, time = 2000) {
            let old = 0
            return function () {
                let newTime = Date.now()
                if (newTime - old < time) {
                    return
                }
                setTimeout(() => {
                    
                    fn()
                }, time)
                old = newTime
            }
        }
        function print() {
            console.log('节流');
        }
        jl.addEventListener('click', debounce(print))
    </script>
</body>

</html>